package hardy.etudejpa.service;

import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.inject.Inject;
import javax.transaction.Transactional;
import org.hardy.util.randomutil.RandomUtil;
import org.springframework.stereotype.Service;
import hardy.etudejpa.model.UserAuthEntity;
import hardy.hibhelper.basecore.SubHelper;

@Service
@Transactional
public class VoTestImpl implements VoTestService{
	@Inject
    private SubHelper helper;
	 
	@Override
	public void saveUser(String phone) {
		 UserAuthEntity userAuthEntity = new UserAuthEntity();
         userAuthEntity.setAddDate(new Date());
         userAuthEntity.setEmail(RandomUtil.getRandomString(5)+"@163.com");
         userAuthEntity.setPassword("123456");
         userAuthEntity.setPhone(phone);
         Random r = new Random();
         userAuthEntity.setRemark(""+r.nextInt(100));
         helper.persist(userAuthEntity);
	}

	@Override
	public List<UserAuthEntity> findUser(UserAuthEntity ua) {
		return helper.getListByEntity(ua, null);
	}

	@Override
	public void batchSaveUser(String[] phone) {
		for(String ph:phone) {
			saveUser(ph);
		}
	}

	@Override
	public void updateEmail(UserAuthEntity ua) {
		helper.saveOrUpdate(ua);
	}
	
	@Override
	public void updatePassword(UserAuthEntity ua) {
		helper.update(ua);
	}

	 
	
	@Override
	public void delete(UserAuthEntity ua) {
		helper.delete(ua);
	}
	
	@Override
	public void deleteF(List<UserAuthEntity> uas) {
		for(UserAuthEntity ua:uas) {
			helper.delete(ua);
		}
	}
	
}
